// pages/daily/daily.js
var app = getApp();
var config = require('../../config.js');
var util = require('../../utils/util.js');
var imgUrl = '';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img_url:imgUrl
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this; 
    wx.request({
      url: config.weekenddailylist,
      success: function (res) {
        if (res.data.success == 0){
          that.setData({
            imageList: res.data.rows,
          })
          that.getCurrDateImg();
        }

      },

      fail: function (error) {
        console.log(error)
      }
    })
  },
  toBigImg:function(e){
    var id = e.currentTarget.id
    var itemImg = this.data.imageList.filter(item => id == item.id);
    var currImgUrl = itemImg[0].imgUrl;
    var currImgObj = itemImg[0];
    this.setData({
      bigImgUrl: currImgUrl,
      current: currImgObj
      
    });
  },
  /**
   * 获取当天对应的图片对象
   */
  getCurrDateImg: function(){
    var that = this;
    var currentTime = Date.now();
    var time = util.timeStamp2String(currentTime);
    // var time = "2018-05-15";
    var itemImg = that.data.imageList.filter(item => time == item.fajiaDate);
    if (itemImg.length > 0){
      var currImgUrl = itemImg[0].imgUrl;
      var currImgObj = itemImg[0];
      that.setData({
        bigImgUrl: currImgUrl,
        current: currImgObj
      });
    }
  },
  /**
    * 分享
    */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '法加日历',
      path: '/pages/daily/daily',
      imageUrl: this.data.bigImgUrl
    }
  },
  saveImg:function(){
    console.log(this.data.bigImgUrl);
    if (this.data.bigImgUrl){
      app.saveImgToPhotosAlbumTap(this.data.bigImgUrl);
    }
    

  }
})